import { useDetail, useList } from "@/hooks";
import { getUserInfoUrl } from "@/command/apiTool";
import { getAction, postAction } from "@/command/netTool";
import * as vant from "vant";
const { showFailToast, showSuccessToast } = vant;
import { useRouter, useRoute } from "vue-router";
export const useRequest = () => {
  const router = useRouter();
  const route = useRoute();
  const userInfo = localStorage.getItem("userInfo") as string;
  const userInfoJSON = JSON.parse(userInfo) as any;
  const confirm = (params: any) => {
    let queryParams = {
      ...params,
      ifPublic: params.ifPublic ? "0" : "1",
    };
    console.log("eee", queryParams);
    postAction(
      "/api/H5/service/helpWork/small/saveInfo",
      { ...queryParams },
      { isResolve: true }
    ).then((e) => {
      showSuccessToast(e.msg || e.data);
      router.back();
    });
  };
  const [workList] = useDetail(
    "/api/H5/util/getDictType?dictType=work_type",
    [],
    {
      // callBack: (data: any[]) => {
      //   return data.filter((e) => e.value != "-1");
      // },
    }
  );
  const [detailInfo] = useDetail(
    getUserInfoUrl({
      dh: "",
      xh: "/api/H5/service/helpWork/small/getInfo",
    }),
    {
      name: userInfoJSON.name,
      phone: userInfoJSON.phone,
    },
    {
      callBack: (e: any) => {
        return {
          ...e,
          ifPublic: e.ifPublic == "0" ? true : false,
        };
      },
    }
  );
  return {
    confirm,
    workList,
    detailInfo,
  };
};
